#include <iostream>
#include <fstream>
#include <string>
#include <ctime>

#include "virtual_graph.cc"

using namespace std;




vector<int> getNumber(string s){
    vector<int> result;
    int cur=0,sum=0;
    bool flag;
    while(cur<s.size()){
        sum=0;
        flag=false;
        while(isdigit(s[cur])){
            flag=true;
            sum = sum*10+s[cur]-'0';
            cur++;
        }
        if(flag){
            result.emplace_back(sum);
        }
        while(!isdigit(s[cur])) cur++;
    }

    return result;
}


int main(){
    clock_t begin,end;
    begin=clock();

    Graph test(9);
    std::ifstream Nodes("Nodes.txt", std::ios::in);
    if(!Nodes.is_open()){
		std::cout<<"Open file Nodes failed"<<std::endl;
		return 0;
	}else{
		std::cout<<"Open file Nodes successed"<<std::endl;
	}
    int node_id = 0;
    int type = 0;
    
    while(Nodes>>node_id){
        Nodes>>type;
        test.addNodes(node_id, type);
    }
    Nodes.close();


    std::ifstream Links("Links.txt", std::ios::in);
     if(!Links.is_open()){
		std::cout<<"Open file Links failed"<<std::endl;
		return 0;
	}else{
		std::cout<<"Open file Links successed"<<std::endl;
	}

    int source_id;
    int ter_id;
    int cost;
    int delay;
    vector<int> units;
    string tmp;
   
    while(Links>>source_id){
        Links>>ter_id>>cost>>delay;
        getline(Links,tmp);
        units=getNumber(tmp);
        test.addLinks(source_id,ter_id,cost,delay,units);
    }
    Links.close();
    test.makeGraph();
    //test.Check();

    virtual_graph vir;
    vir.SetupTopology(&test);
    vir.makeVirtualGraph();
    vir.Check();
 

    std::ifstream Flows("Flows.txt", std::ios::in);
     if(!Flows.is_open()){
		std::cout<<"Open file Flows failed"<<std::endl;
		return 0;
	}else{
		std::cout<<"Open file Flows successed"<<std::endl;
	}

    int from;
    int to;

    while(Flows>>from){
        Flows>>to;
        Flow fl(from,to);
        Path result=vir.FindPath(fl);
        result.Print();
    }

    end=clock();
    cout<<"总花费时间："<<double(end-begin)/CLOCKS_PER_SEC<<'s'<<endl;
    
    return 0;
}